package Simulator;

import Shared.AmbType;
import Shared.MapPosition;

/**
 * The AmbulanceGenerator module, see Architecture report for specifications.
 */

public class AmbulanceGenerator {

	private EnvironmentDatabase db;
	private final static double averageEquiped = 0.3;

	private static AmbulanceGenerator singleton = new AmbulanceGenerator();

	/**
	 * @return the unique RadioSoftware instance.
	 */
	public static AmbulanceGenerator getInstance() {
		return singleton;
	}

	private AmbulanceGenerator() {
		this.db = EnvironmentDatabase.getInstance();
	}

	/**
	 * Create an ambulance (randomly equipped or not) and put it in the
	 * environment database. Register it.
	 * 
	 * @param pos
	 *            the initial ambulance position.
	 */
	public RealAmbulance createAmbulance(MapPosition pos) {

		AmbType realType = Math.random() > averageEquiped ? AmbType.EQUIPED : AmbType.SIMPLE;

		return this.createAmbulance(pos, realType);

	}

	/**
	 * Create an ambulance of type "type" and put it in the environment
	 * database. Register it.
	 * 
	 * @param pos
	 *            the initial ambulance position.
	 * @param type
	 *            the ambulance type.
	 */
	public RealAmbulance createAmbulance(MapPosition pos, AmbType type) {

		RealAmbulance realAmb = new RealAmbulance(type, pos);

		this.db.addAmb(realAmb);

		realAmb.getMdt().register();

		return realAmb; // for test
	}

}
